#!/usr/bin/python
# -*-coding: UTF-8 -*-
"""
# Time: 2025/4/20 14:40
# @Project_name: PROJECT_NAME
"""
import json


a = 1
b = 'abc'
c = True
d = False
e = 3.1415

str1 = "abc d "
str1.isupper()
print("全大写：", str1.isupper())
print("转大写：", str1.upper())
str2 = str1.split()  # 默认按空格分割
print("字符转列表：", str2)
str1 = "a,b,c d "
str2 = str1.split(",")  # 默认按空格分割
print("字符转列表：", str2)
print("剔除空格：", str1.strip())

list1 = [1, 2, "周先生"]
len(list1)
list1.append("郭先生")
a1 = list1[0]
list1.remove(1)
print(list1)
list1[0] = '毛先生'
print(list1)

a = [1, 3, 12, 0]
a.sort()
print("列表永久排序：", a)
a.reverse()
print("列表倒着打印：", a)

tuple1 = (1, 2, 3)
tuple2 = (1, '2', 3)
tuple3 = (1, '2', "周先生")
tupleToList = list(tuple1)
print(tupleToList)
for i in range(len(list1)):
    print(list1[i])

dicts = {"name": "周先生", "age": 28}
name = dicts.get("names")
dicts["gender"] = "男"
dicts["age"] = "29"
print(dicts)

dicts.update({"age": 30, "job": "总理"})
print(dicts)
del dicts["job"]
print(dicts)

for key, value in dicts.items():
    print(key, ":", value)


numbers = "[1, 2, 3]"
jsonStrToList = json.loads(numbers)
print("json字符串转列表：", jsonStrToList)

lists = [1, 2, 3]
listToJsonStr = json.dumps(lists)
print("列表转json字符串：", type(listToJsonStr), listToJsonStr)

dicts = '{"name": "周先生", "age": 28}'
jsonStrToDict = json.loads(dicts)
print("json字符串转字典：", jsonStrToDict)

print("~~~~~~~~嵌套字典~~~~~~")
dicts = '{"name": "周先生", "age": 28, "hobby":["看书", "写字", "为人民服务"]}'
jsonStrToDict = json.loads(dicts)
print("嵌套json字符串转列表：", jsonStrToDict)
hobby1 = jsonStrToDict.get('hobby')[1]
print(hobby1)
hobby0 = jsonStrToDict['hobby'][0]
print(hobby0)


